//定义函数：构建要显示的时间日期字符串
function showTime()
{
    //创建Date对象
    var today = new Date();
    //分别取出年、月、日、时、分、秒
    var year = today.getFullYear();
    var month = today.getMonth()+1;
    var day = today.getDate();
    var hours = today.getHours();
    var minutes = today.getMinutes();
    var seconds = today.getSeconds();
    var weeks=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    var num=today.getDay();
    //如果是单个数，则前面补0
    month  = month<10  ? "0"+month : month;
    day  = day <10  ? "0"+day : day;
    hours  = hours<10  ? "0"+hours : hours;
    minutes = minutes<10 ? "0"+minutes : minutes;
    seconds = seconds<10 ? "0"+seconds : seconds;

    //构建要输出的字符串
    var str = "今天是："+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+" "+weeks[num];

    //获取id=result的对象
    var obj = document.getElementById("result");
    //将str的内容写入到id=result的<div>中去
    obj.innerHTML = str;
    //延时器
    window.setTimeout("showTime()",1000);


    // var weeks=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    // var today = new Date();  var num = today.getDay();
    // document.write("今天:" + weeks[num]);
}

